package com.main.crossdomaineventmanagement.event.exception;

import com.main.common.base.resp.RespBody;
import com.main.common.base.resp.RespCode;
import com.main.common.utils.exceptions.StackTraceLog;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(EventPublishException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public RespBody<EventPublishException> handleEventPublishException(EventPublishException e) {
        StackTraceLog stackTraceLog = new StackTraceLog();
        stackTraceLog.saveStackTraceLog(e);
        return RespBody.fail(RespCode.INTERNAL_SERVER_ERROR,"handleEventPublishException",e);
    }
}